import { IAssemblyDocTreeNode } from '@amcax/base';
import { personalWorkspaceDocsInfo } from '@app-cad/pages/product-support/assembly-funcs';

export const assemblyNodeTitleModifier = (title: string, docName?: string) => {
  if (docName) {
    title = title.startsWith(`${docName}.`)
      ? title.slice(docName.length + 1)
      : title;
    return `${docName} <${title}>`;
  }

  return title;
};

export const assemblyGetNodeTitleModified = (node: IAssemblyDocTreeNode) => {
  const docName = personalWorkspaceDocsInfo.find(
    ({ documentUuid }) => documentUuid === node.assembly?.docid,
  )?.name;

  return assemblyNodeTitleModifier(node.title, docName);
};
